package com.jvtd.demo.im.listener;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Toast;

import com.jvtd.rong_im.listener.BaseConversationListBehaviorListener;

import io.rong.imkit.model.UIConversation;
import io.rong.imlib.model.Conversation;

/*
 * Create by Jack Zhang
 */
public class MyConversationListBehaviorListener extends BaseConversationListBehaviorListener
{

  private final Context context;

  public MyConversationListBehaviorListener(Context context)
  {
    this.context = context;
  }

  @Override
  public boolean onConversationPortraitClick(Context context, Conversation.ConversationType conversationType, String targetId)
  {
    showToastMsg("点击了" + targetId + "的头像");
    return super.onConversationPortraitClick(context, conversationType, targetId);
  }

  @Override
  public boolean onConversationPortraitLongClick(Context context, Conversation.ConversationType conversationType, String targetId)
  {
    showToastMsg("长按了" + targetId + "的头像");
    return super.onConversationPortraitLongClick(context, conversationType, targetId);
  }

  @Override
  public boolean onConversationLongClick(Context context, View view, UIConversation uiConversation)
  {
    showToastMsg("长按了会话消息");
    return super.onConversationLongClick(context, view, uiConversation);
  }

  @Override
  public boolean onConversationClick(Context context, View view, UIConversation uiConversation)
  {
    showToastMsg("点击了会话消息");
    return super.onConversationClick(context, view, uiConversation);
  }

  private void showToastMsg(String string)
  {
    new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, string, Toast.LENGTH_SHORT).show());
  }
}
